#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;


class Solution
{
public:
    int breakfastNumber(vector<int>& staple, vector<int>& drinks, int x) {
        sort(staple.begin(), staple.end());
        sort(drinks.begin(), drinks.end());
        int len1 = staple.size();
        int len2 = drinks.size();
        int left = 0, right = len2 - 1;
        long ret = 0;

        while (left != len1 && right >= 0)
        {
            if (staple[left] + drinks[right] > x)
            {
                --right;
            }
            else
            {
                ret += right + 1;
                left++;
                right %= 1000000007;
            }
        }
        return ret %= 1000000007;;
    }
};

int main()
{
    vector<int> v1 = { 6,1,9,2,9,9,3,4 };
    vector<int> v2 = { 2,7,10,2,9,2,1,3 };
    Solution s1;
    s1.breakfastNumber(v1, v2, 2);


	return 0;
}